package lion.blog.tag;

import java.util.Iterator;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.jstl.core.LoopTagSupport;

import lion.dev.lang.MapJ;
import lion.framework.core.db.DB;
import lion.framework.core.db.SessionFactory;
import lion.framework.core.db.paging.SQLPagingFactory;
import lombok.Setter;

/**
 * 最新评论
 * 
 * @author lion
 * @email hl_0074@sina.com
 * @date 2015年12月3日
 */
public class LatestCommentTag extends LoopTagSupport {

	private static final long serialVersionUID = 1L;

	@Setter
	private int count = 5;

	private Iterator<MapJ> iter;

	@Override
	protected boolean hasNext() throws JspTagException {

		return iter.hasNext();
	}

	@Override
	protected Object next() throws JspTagException {

		return iter.next();
	}

	@Override
	protected void prepare() throws JspTagException {

		DB db = SessionFactory.getCurrentDB();

		String sql = SQLPagingFactory.paging(db.getType(), "select bc.*,ba.title atitle,ba.id aid from BlogComment bc,BlogArticle ba where bc.article = ba.id order by bc.id desc",
				0, count);
		iter = db.query(sql).getRows().iterator();
	}
}
